View.vue<template>
<h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="user.name">
  <input type="text" placeholder="请输入员工工资" v-model="user.salary">
  <input type="text" placeholder="请输入员工岗位" v-model="user.job">
  <button @click="add">点我添加</button>
  <hr>
  <table border="1">
    <tr>
      <td>编号</td>
      <td>员工姓名</td>
      <td>员工工资</td>
      <td>员工岗位</td>
    </tr>
    <tr v-for="(item,index) in arr">
      <td>{{index+1}}</td>
      <td>{{item.name}}</td>
      <td>{{item.salary}}</td>
      <td>{{item.job}}</td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

const user=ref({
  name:'',
  salary:'',
  job:''
}
)

const arr=ref([]);
const add=()=>{
  if (user.value.name.trim()=='' ||user.value.salary.trim()==''||user.value.job.trim()==''){
    alert('请输入完整员工信息');
    return;
  }
  arr.value.push(user.value);
  //存入后清空输入框数据
  user.value={
    name:'',
    salary:'',
    job:''
  }
  console.log(user.value);
}

</script>


<style scoped>

</style>